package com.zjw.xm.xmorder.controller;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;


import com.yc.common.bean.Result;
import com.zjw.xm.entity.CrBook;
import com.zjw.xm.entity.CrUser;
import com.zjw.xm.entity.CrCart;
import com.zjw.xm.xmorder.mapper.CrCartMapper;
import com.zjw.xm.xmorder.service.impl.CrCartServiceImpl;
import org.apache.catalina.User;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zjw1
 * @since 2022-08-03
 */
@RestController
@RequestMapping("/xm/crCart")
public class CrCartController {

    @Resource
    CrCartMapper crCartMapper;
    @Resource
    CrCartServiceImpl service;

    @RequestMapping("addCart")
    public Result addCart(CrCart crCart){
        LambdaQueryWrapper<CrCart> lqw = new LambdaQueryWrapper();
        lqw.eq(CrCart::getUid,crCart.getUid());
        lqw.eq(CrCart::getBid,crCart.getBid());
        CrCart dbCrcate = crCartMapper.selectOne(lqw);
        if ( dbCrcate != null ){
            dbCrcate.setCnt(dbCrcate.getCnt()+1);
        }else {
            dbCrcate = crCart;
            dbCrcate.setCnt(1);
        }
        service.saveOrUpdate(dbCrcate);
        return Result.success("添加购物车成功",null);
    }


}

